import Vue from 'vue'
import VueI18n from 'vue-i18n'
import EL_EN from 'element-ui/lib/locale/lang/en'
import EL_ZH_CN from 'element-ui/lib/locale/lang/zh-CN'
// custom
import GB_EN from './langs/en'
import GB_ZH_CN from './langs/zh_CN'
// train
import TRAIN_EN from './langs/train/en'
import TRAIN_ZH_CN from './langs/train/zh_CN'
import JS_TRAIN_EN from './langs/train/js_en'
import JS_TRAIN_ZH_CN from './langs/train/js_zh_CN'

Vue.use(VueI18n)

// 默认语言
let STORE_KEY_LANG = 'HT_LOCALE' // 记忆key localStore
let STORE_LANG = localStorage.getItem(STORE_KEY_LANG)
let DEFAULT_LANG = STORE_LANG || 'zh-CN'
let I18N_CONFIG = [
  {
    title: '中文',
    key: 'zh-CN'
  },
  {
    title: 'English',
    key: 'en'
  }
]
let locales = {
  'en': {
    ...GB_EN,
    ...EL_EN,
    ...JS_TRAIN_EN,
    // train
    train: {
      ...TRAIN_EN
    }
  },
  'zh-CN': {
    ...GB_ZH_CN,
    ...EL_ZH_CN,
    ...JS_TRAIN_ZH_CN,
    // train
    train: {
      ...TRAIN_ZH_CN
    }
  }
}

Vue.config.lang = DEFAULT_LANG
Object.keys(locales).forEach(function (lang) {
  Vue.locale(lang, locales[lang])
})

export {
  // i18n,
  I18N_CONFIG,
  DEFAULT_LANG,
  STORE_KEY_LANG
}

// let i18n = new VueI18n({
//   locale: DEFAULT_LANG, // 默认设定
//   messages: {
//     'en': {
//       ...GB_EN,
//       ...EL_EN,
//       ...JS_TRAIN_EN,
//       // train
//       train: {
//         ...TRAIN_EN
//       }
//     },
//     'zh-CN': {
//       ...GB_ZH_CN,
//       ...EL_ZH_CN,
//       ...JS_TRAIN_ZH_CN,
//       // train
//       train: {
//         ...TRAIN_ZH_CN
//       }
//     }
//   }
// })
